package com.ymttest.database.sqlwapper.shenqisettlement;

import java.util.HashMap;
import java.util.List;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.shenqisettlement.DistributorSettlement;

public class DistributorSettlementWrapper {

	SqlManager manager;

	public DistributorSettlementWrapper() {
		manager = new SqlManager("shenqisettlement");
	}

	@SuppressWarnings("unchecked")
	public DistributorSettlement selectByPrimaryKey(long id) {

		DistributorSettlement distributorSettlement = new DistributorSettlement();
		List<DistributorSettlement> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributorSettlement = result.get(0);
		}

		return distributorSettlement;
	}
	
	@SuppressWarnings("unchecked")
	public DistributorSettlement selectByPaymentIdAndOrderId(long paymentId, Long orderId) {

		HashMap<String, Long> map = new HashMap<>();
		
		map.put("payment_id", paymentId);
		map.put("order_id", orderId);
		
		DistributorSettlement distributorSettlement = null;
		List<DistributorSettlement> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.shenqisettlement.DistributorSettlementMapper.selectByPaymentIdAndOrderId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributorSettlement = result.get(0);
		}

		return distributorSettlement;
	}

	@SuppressWarnings("unchecked")
	public int updateShengpaySharingExecuteStatusByOrderId(long orderId, int shengpaySharingExecuteStatus) {

		HashMap<String, Object> map = new HashMap<>();

		map.put("order_id", orderId);
		map.put("shengpay_sharing_execute_status", shengpaySharingExecuteStatus);

		int result = manager
				.update("com.ymttest.database.mapping.shenqisettlement.DistributorSettlementMapper.updateShengpaySharingExecuteStatusByOrderId",
						map);
		manager.commit();

		if (result == 0) {
			Logger.comment("没有数据更新");
		}

		return result;
	}
	
	public static void main(String[] args) {
		
		DistributorSettlementWrapper wrapper = new DistributorSettlementWrapper();
		
		System.out.println(wrapper.updateShengpaySharingExecuteStatusByOrderId(14333210367L, 1));
	}
}
